package linkwechat.controller.system;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import linkwechat.pojo.ReturnData;
import linkwechat.pojo.ReturnEnum;
import linkwechat.pojo.SysDept;
import linkwechat.sysservice.SysDeptService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("sysdept")
@RestController
public class SysDeptController {

    @Resource
    SysDeptService sysDeptService;


//    部门查询
    @RequestMapping("select")
    public ReturnData deptSelect(){
        List<SysDept> list = sysDeptService.SelectDeptList();
        return ReturnData.respSuccess(list);
    }


    //    部门条件查询
    @RequestMapping("selectLike")
    public ReturnData SelectDeptLike(SysDept sysDept){
        List<SysDept> list = sysDeptService.SelectDeptLike(sysDept);
        return ReturnData.respSuccess(list);
    }


    //    部门新增
    @RequestMapping("deptAdd")
    public ReturnData DeptAdd(SysDept sysDept){
        int i = sysDeptService.AddDept(sysDept);
        return ReturnData.setResp(ReturnEnum.APPEND_SUCCEED,i);
    }


//     根据部门Id查询
    @RequestMapping("selectById")
    public ReturnData SelectById(Long deptId){
        QueryWrapper<SysDept> queryWrapper = new QueryWrapper<>();
        List<SysDept> list = sysDeptService.list(queryWrapper.eq("dept_id",deptId));
        return ReturnData.respSuccess(list);
    }

    //     根据部门父ID查询
    @RequestMapping("SelectParentById")
    public ReturnData SelectParentById(Long parentId){
        QueryWrapper<SysDept> queryWrapper = new QueryWrapper<>();
        List<SysDept> list = sysDeptService.list(queryWrapper.eq("parent_id",parentId));
        return ReturnData.respSuccess(list);
    }



    //    修改部门信息
    @RequestMapping("updateDept")
    public ReturnData UpdateDept(SysDept sysDept) {
        System.out.println(sysDept);
        boolean b = sysDeptService.updateById(sysDept);
        return ReturnData.setResp(ReturnEnum.MODIFY_SUCCEED,b);
    }

    //   根据部门编号删除
    @RequestMapping("removeById")
    public ReturnData DeleteDept(Long deptId) {
        int i = sysDeptService.DeleteDept(deptId);
        return ReturnData.setResp(ReturnEnum.REMOVE_SUCCEED,i);
    }






}
